//
//  SXGetBundleData.m
//  Pods-SXDataManager_Example
//
//  Created by 王水鑫 on 2019/1/6.
//

#import "SXGetBundleData.h"

@implementation SXGetBundleData

// 获取bundle中文件的数据
+ (NSData *)dataPathForResource:(nullable NSString *)resource ofType:(nullable NSString *)type {
    NSBundle *bundlePath = [NSBundle performSelector:@selector(SXDataManager_bundle) withObject:nil];
    NSString *pathString;
    if (type == nil) {
        pathString = [bundlePath pathForResource:resource ofType:nil];
    } else {
        pathString = [bundlePath pathForResource:resource ofType:type];
    }
    // 防崩机制
    if (pathString == nil) {
        return nil;
    }
    NSData *data = [NSData dataWithContentsOfFile:pathString];
    return data;
}

// 获取bundle中image
+ (UIImage *)SXImageName:(nullable NSString *)imageName {
    NSBundle *bundlePath = [NSBundle performSelector:@selector(SXDataManager_bundle) withObject:nil];
    UIImage *image = [UIImage imageNamed:imageName inBundle:bundlePath compatibleWithTraitCollection:nil];
    return image;
}

#pragma mark - 占位方法
+ (void)SXDataManager_bundle {
    
}

@end
